<?php
// $Id: form_example_states.inc,v 1.8 2010/12/12 07:10:49 rfay Exp $

/**
 * @file
 * An example of how to use the new #states Form API element, allowing
 * dynamic form behavior with very simple setup.
 */

function genotypes_table_display()
{
	$tbl_header = array();
	$tbl_header[] = array("data" => "Genotype Name, Author");
	$tbl_header[] = array("data" => "Size");
	$tbl_header[] = array("data" => "Action");
	$tbl_header[] = array("data" => "Genotype");
	
	//$sql = "SELECT * FROM genotypes";
	$query = db_select('genotypes', 'g');
	$query->join('users', 'u', 'u.uid = g.us_id');
	$genotypes = $query->fields('g', array('id', 'name', 'count_p', 'count_j', 'count_n', 'count_c', 'geno_html_short'))->fields('u', array('name'))->execute();
	
	/*
	
	$genotype = $genotypes->fetchAssoc();
	echo "<pre>";
	var_dump($genotype);
	die();
	*/
	
	
	while($genotype = $genotypes->fetchAssoc()){
	  $rows[] = array(
	    array('data' => $genotype['name'] . ',<br> by ' .
				$genotype['u_name']),
	    array('data' => 'P: ' . $genotype['count_p'] . '<br>' . 
				'J: ' . $genotype['count_j'] . '<br>' .
				'N: ' . $genotype['count_n'] . '<br>' .
				'C: ' . $genotype['count_c']),
	    array('data' => l('show details', 'genotype_details/'.$genotype['id'])),
	    array('data' => $genotype['geno_html_short'])
	  );
	}
	
	/*
	$rows = array(
	      // Simple row
	      array(
	        'Cell 1', 'Cell 2', 'Cell 3'
	      ),
	      // Row with attributes on the row and some of its cells.
	      /*array(
	        'data' => array('Cell 1', array('data' => 'Cell 2', 'colspan' => 2)), 'class' => array('funky')
	      )
	    );
	*/
	
	$variables = array(
	  "header" => $tbl_header, 
	  "rows" => $rows, 
	  "attributes" => array(), 
	  "caption" => "", 
	  "colgroups" => array(),
	  "sticky" => "",
	  "empty" => "");
	
	$html = theme_table($variables);
	return $html;
}
?>
